package com.example.usb.util;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.Log;

import com.example.usb.ai.AiV3Bean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created Date 2019/4/30
 *
 * @author liangkun
 * description：绘制人脸框
 */
public class DrawFaceUtil {
    /**
     * 通过返回人脸的数据得到人脸坐标点
     *
     * @param locations 位置集合
     * @return
     */
    private List<float[]> returnFloats(List<AiV3Bean.FaceList.Location> locations) {
        List<float[]> list = new ArrayList<>();
        for (int i = 0; i < locations.size(); i++) {
            AiV3Bean.FaceList.Location location = locations.get(i);
            float[] pointXY = ImageUtils.getFacePoint(location);
            list.add(pointXY);
        }
        return list;
    }

    //    float[] floats = new float[]{150,200,350,200,350,200,350,600,350,600,150,600,150,600,150,200};
//    float[] floats2 = new float[]{250,300,450,300,450,300,450,600,450,600,250,600,250,600,250,300};
    private Bitmap drawFaceBitmap(Bitmap bitmap, List<float[]> floats) {
        /**
         * 注意多个createBiamap重载函数，必须是可变位图对应的重载才能绘制
         * bitmap: 原图像
         * pixInterval: 网格线的横竖间隔，单位:像素
         */
        Bitmap copy = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);  //很重要
        Log.d("kun", "width " + bitmap.getWidth() + "height " + bitmap.getHeight());
        Canvas canvas = new Canvas(copy);  //创建画布
        Paint paint = new Paint();  //画笔
        paint.setStrokeWidth(2);  //设置线宽。单位为像素
        paint.setAntiAlias(true); //抗锯齿
        paint.setStyle(Paint.Style.STROKE);//设置风格为空心
        paint.setColor(Color.RED);  //画笔颜色
        canvas.drawBitmap(bitmap, new Matrix(), paint);  //在画布上画一个和bitmap一模一样的图
        for (int i = 0; i < floats.size(); i++) {
            float[] floatItem = floats.get(i);
            canvas.drawLines(floatItem, paint);
        }
        return copy;
    }
}
